# @Version        : 1.0
# @Update Time    : 2025/3/14 16:54
# @File           : coupon_view.py
# @IDE            : PyCharm
# @Desc           : 文件描述信息

import flet as ft

class CouponView(ft.Column):
    def __init__(self, page: ft.Page, params: dict = None):
        super().__init__()
        self.page = page
        self.params = params
        self.expand = True
        self.build_interface()

    def build_interface(self):
        # 顶部导航栏
        app_bar = ft.Container(
            content=ft.Row([
                ft.Text("优惠券", size=20, weight=ft.FontWeight.BOLD)
            ], alignment=ft.MainAxisAlignment.START),
            padding=15,
            border=ft.border.only(bottom=ft.border.BorderSide(1, ft.colors.GREY_300))
        )

        # 优惠券卡片列表
        coupons = ft.ListView(
            controls=[
                self._build_coupon_card(
                    bg_color=ft.colors.AMBER_200,
                    title="全部商品",
                    discount="50%",
                    subtext="折價",
                    description="全场商品通用优惠"
                ),
                self._build_coupon_card(
                    bg_color=ft.colors.GREEN_200,
                    title="新会员折扣",
                    discount="40%",
                    subtext="首单专享",
                    description="新用户注册即可使用"
                ),
                self._build_coupon_card(
                    bg_color=ft.colors.AMBER_200,
                    title="周五可用",
                    discount="买2赠1",
                    subtext="周末狂欢",
                    description="每周五限定商品可用"
                )
            ],
            spacing=20,
            padding=20
        )

        self.controls = [
            ft.Column(controls=[app_bar], spacing=0),
            ft.Container(coupons, expand=True)
        ]

    def _build_coupon_card(self, bg_color, title, discount, subtext, description):
        return ft.Container(
            content=ft.Column([
                ft.Row([
                    ft.Column([
                        ft.Text(title, size=18, weight=ft.FontWeight.BOLD),
                        ft.Text(subtext, color=ft.colors.GREY_600)
                    ], spacing=5),
                    ft.Text(discount,
                          size=32,
                          weight=ft.FontWeight.BOLD,
                          color=ft.colors.RED_600)
                ], alignment=ft.MainAxisAlignment.SPACE_BETWEEN),
                ft.Divider(height=20),
                ft.Text(description, color=ft.colors.GREY_800),
                ft.Container(
                    content=ft.ElevatedButton(
                        "立即使用",
                        style=ft.ButtonStyle(
                            color=ft.colors.AMBER_800,
                            bgcolor=ft.colors.WHITE,
                            shape=ft.RoundedRectangleBorder(radius=20)
                        )
                    ),
                    alignment=ft.alignment.center_right
                )
            ], spacing=10),
            padding=20,
            bgcolor=bg_color,
            border_radius=15,
            shadow=ft.BoxShadow(
                spread_radius=2,
                blur_radius=5,
                color=ft.colors.GREY_400,
                offset=ft.Offset(2, 2)
            )
        )
